package com.engine4cloud.tdf.supervision.convert;

import com.engine4cloud.tdf.supervision.dto.DcpgCrimeNameDTO;
import com.engine4cloud.tdf.supervision.dto.result.DcpgInvCrimeNameResultDTO;
import com.engine4cloud.tdf.supervision.entity.DcpgInvCrimeNameEntity;
import com.engine4cloud.tdf.supervision.entity.DcpgInvestigationEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface DcpgInvCrimeNameConvert {
    DcpgInvCrimeNameConvert INSTANCE = Mappers.getMapper(DcpgInvCrimeNameConvert.class);

    @Mapping(target = "id", ignore = true)
    DcpgInvCrimeNameEntity create(DcpgInvestigationEntity investigation, String zm);

    DcpgInvCrimeNameEntity update(DcpgInvestigationEntity investigation, String zm);

    DcpgInvCrimeNameResultDTO convert(DcpgInvCrimeNameEntity entity);

    DcpgCrimeNameDTO convert(DcpgInvCrimeNameResultDTO s);

    default List<DcpgInvCrimeNameEntity> convert(DcpgInvestigationEntity entity, List<DcpgCrimeNameDTO> crimeList) {
        List<DcpgInvCrimeNameEntity> resultList = new ArrayList<>();
        crimeList.forEach(crime -> resultList.add(create(entity, crime.getZm())));
        return resultList;
    }

}
